import * as THREE from 'three';

const scene = new THREE.Scene();
const camera = new THREE.PerspectiveCamera(75, window.innerWidth / window.innerHeight, 0.1, 1000);
const renderer = new THREE.WebGLRenderer();
renderer.setSize(window.innerWidth, window.innerHeight);
document.body.appendChild(renderer.domElement);

const geometry = new THREE.BoxGeometry(1, 1, 1);
const material = new THREE.MeshBasicMaterial({ color: 0x00ff00 });
const mesh = new THREE.Mesh(geometry, material);
mesh.position.x = -2;
mesh.scale.x = 4;
scene.add(mesh);
console.log(mesh);


const axesHelper = new THREE.AxesHelper(2);
scene.add(axesHelper);


// A表示3D空间一个点的位置坐标
const A = new THREE.Vector3(5, 0, 0);
// 黄色小球可视化坐标点A 
const Amesh = createSphereMesh(0xffff00,2);
Amesh.position.copy(A);
scene.add(Amesh);
// 创建小球mesh
function createSphereMesh(color,R) {
    const geometry = new THREE.SphereGeometry(R);
    const material = new THREE.MeshBasicMaterial({
        color: color,
    });
    const mesh = new THREE.Mesh(geometry, material);
    return mesh;
}
// Amesh.quaternion.setFromAxisAngle(new THREE.Vector3(0, 0, 1), Math.PI / 2);

// const quaternion = new THREE.Quaternion();
// 绕z轴旋转90度
// Amesh.quaternion.setFromAxisAngle(new THREE.Vector3(0,0,1),Math.PI/2);
// Amesh.position.applyQuaternion(Amesh.quaternion);
// // 通过四元数旋转A点：把A点绕z轴旋转90度生成一个新的坐标点B
// const B = A.clone().applyQuaternion(quaternion);
// console.log('B',B);//查看旋转后坐标
// // // 红色小球可视化坐标点B 
// // const Bmesh = createSphereMesh(0xff0000,2);
// // Bmesh.position.copy(B);
// // scene.add(Bmesh);


camera.position.z = 15;

renderer.render(scene, camera);
